// Problem 027：Quadratic primes
// Considering quadratics of the form: n^2+a*n+b, where |a|<1000,|b|<=1000.
// Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0.

package main

import (
	"fmt"
	"projecteuler/euler"
)

func p027() {
	max, ab := 0, 1
	euler.FillPrime(1000)
	for _, b := range euler.PrimeList[1:] {
		if b > 1000 {
			break
		}
		for a := -999; a < 1000; a += 2 {
			c, n := 1, 0
			for {
				n++
				if euler.IsPrime(n*n + a*n + b) {
					c++
				} else {
					break
				}
			}
			if c > max {
				max, ab = c, a*b
			}
		}
	}
	fmt.Println("Problem 027:", ab)
}
